﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Modelo.Modulos.ClasesModelado;
using Logica.Modulos.ClasesLogica;

namespace ProyectoFinal
{
    public partial class frmComentarios : Form
    {
        private int idTarea;
        public int IdTarea
        {
            get { return idTarea; }
            set { idTarea = value; }
        }
        public frmComentarios()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnAgregar_Click(object sender, EventArgs e)
        {

                try
                {
                    // if (ValidacionesCampos() == true)
                    {
                        ComentarioMod objMod = new ComentarioMod();
                        objMod.Comentario = txtComentario.Text;
                        objMod.FechaComentario = DateTime.Now;
                        objMod.IdTarea = idTarea;

                        ComentarioLog Logica = new ComentarioLog();
                        Logica.InsertarTarea(objMod);

                        Close();
                    }



                }
                catch (Exception exc)
                {

                    MessageBox.Show(exc.Message, "Error del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            
        }

        private void frmComentarios_Load(object sender, EventArgs e)
        {
            CargarGrid("Cargar");
        }

        public void CargarGrid(string Accion_Form)
        {
            if ((Accion_Form == "Agregar") || (Accion_Form == "Cargar") || (Accion_Form == "Editar"))
            {
                try
                {
                    dataGridView1.Rows.Clear();
                    ComentarioLog logica = new ComentarioLog();
                    ComentarioMod obj = new ComentarioMod();
                    obj.IdTarea = idTarea;
                    List<ComentarioMod> listaComentarios = logica.ConsultarComentaryId(obj);

                    for (int i = 0; i < listaComentarios.Count; i++)
                    {
                        dataGridView1.Rows.Add();
                        dataGridView1.Rows[i].Cells[0].Value = listaComentarios[i].IdComentario;
                        dataGridView1.Rows[i].Cells[1].Value = listaComentarios[i].Comentario;
                        dataGridView1.Rows[i].Cells[2].Value = listaComentarios[i].FechaComentario;

                    }
                }
                catch (Exception)
                {
                    
                    throw;
                }
                
            }
        }

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            try
            {
                
                int Idindice = dataGridView1.SelectedRows[0].Index;
                int Ideliminar = Convert.ToInt32(dataGridView1[0, Idindice].Value);

                ComentarioMod objMod = new ComentarioMod();
                objMod.IdComentario = Ideliminar;


                ComentarioLog Logica = new ComentarioLog();
                Logica.EliminarComentario(objMod);

                CargarGrid("Cargar");
            }
            catch (Exception exc)
            {

                MessageBox.Show(exc.Message, "Error del Sistema", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
